﻿Imports System.Collections.ObjectModel

<DebuggerDisplay("State #{Index}")>
Public Class NFAState
    Private m_outEdges As List(Of NFAEdge)

    Friend Sub New()
        m_outEdges = New List(Of NFAEdge)
    End Sub

    Public ReadOnly Property OutEdges() As ReadOnlyCollection(Of NFAEdge)
        Get
            Return m_outEdges.AsReadOnly()
        End Get
    End Property

    Public Sub AddEdge(ByVal condition As Char, ByVal targetState As NFAState)
        CodeContract.RequiresArgumentNotNull(targetState, "targetState")
        m_outEdges.Add(New NFAEdge(condition, targetState))
    End Sub

    Public Sub AddEdge(ByVal condition As CharRange, ByVal targetState As NFAState)
        CodeContract.RequiresArgumentNotNull(targetState, "targetState")
        m_outEdges.Add(New NFAEdge(condition, targetState))
    End Sub

    ''' <summary>
    ''' Adds an empty (epsilon) edge
    ''' </summary>
    ''' <param name="targetState">The target state that the edge connects to</param>
    ''' <remarks></remarks>
    Public Sub AddEdge(ByVal targetState As NFAState)
        CodeContract.RequiresArgumentNotNull(targetState, "targetState")
        m_outEdges.Add(New NFAEdge(targetState))
    End Sub

    Public Sub AddEdge(ByVal edge As NFAEdge)
        CodeContract.RequiresArgumentNotNull(edge, "edge")

        m_outEdges.Add(edge)
    End Sub

    Public ReadOnly Property IsAcceptState() As Boolean
        Get
            Return TokenTypeIndex <> 0
        End Get
    End Property

    Friend Property TokenTypeIndex As Integer

    Private m_index As Integer
    Public Property Index() As Integer
        Get
            Return m_index
        End Get
        Friend Set(ByVal value As Integer)
            m_index = value
        End Set
    End Property

    Private m_priority As Integer
    Public Property Priority() As Integer
        Get
            Return m_priority
        End Get
        Friend Set(ByVal value As Integer)
            m_priority = value
        End Set
    End Property
End Class
